<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>generator</title>
</head>
<body>

<script>

  function * myGenerator() {
    console.log('开始执行');
    let result = yield 'hello';
    console.log(result);
    console.log('暂停后 再次执行')
    yield 'generator';
    console.log('遍历完毕...')
  }
  //返回指针对象
  let mg = myGenerator();
  console.log(mg.next());;//next()返回值是{value:xxx,done:xxx}
  console.log(mg.next());;//next()返回值是{value:xxx,done:xxx}
  console.log(mg.next());;//next()返回值是{value:xxx,done:xxx} value的值是yield后面执行后的结果
  
  //可以通过next()传入参数指定yield后面执行结果后的值
  
  
  //对象的Symbol.iterator属性 指向遍历器对象
  let obj = {username: 'kobe',age:20};
  obj[Symbol.iterator] = function* myTest(){
    yield 1;
    yield 12;
    yield 13;
  }
  
  for(let i of obj){
    console.log(i);//1,12,13
  }
  
  
  
</script>
</body>
</html>